<%-- 
    Document   : index
    Created on : 15-mar-2012, 13:00:44
    Author     : Maillo
--%>

<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    //Conexion BBDD
    //*****************************************************************
    String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    String connectionURL = "jdbc:derby://localhost:1527/ecommerce;create=true";
    String queryString = "select * from productos";
    try {
        Class.forName(driver);
    } catch (java.lang.ClassNotFoundException e) {
        e.getMessage();
    }
    Connection conn;

    //*****************************************************************
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/index.css" type="text/css" />
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
        <script type="text/javascript" src="js/ajax.js"></script>

        <script type="text/javascript">
            $(document).ready(function (){
                //alert("asd");
                $('.txtcat').click(function(event){
                    
                    var $_categoria = $(this).text();
                    
                        $.ajax({
                            type : "POST",
                            url : "filtrador.jsp",
                            data : "categoria="+$_categoria,
                            async : true,
                            success : function(datos) {
                               var $_tabla = datos;
                               alert($_tabla);
                               $('#menu_ppal').empty();
                               $('#menu_ppal').html($_tabla);
                               
                           }
                       });
                });
 
            });
           
            
        
        </script>
        <title>ecommerce</title>
    </head>
    <body>
        <h1>Tienda Virtual!</h1>
        <div id="menu_izquierdo">

            <fieldset>
                <legend>Menu</legend>
                <ul>
                    <li>
                        <a href="login.jsp">Administración</a>
                    </li>
                    <div id="categorias">
                        <li>
                            Categorias
                            <ul class="txtcat">
                                Alimentación
                            </ul>
                            <ul class="txtcat">
                                Drogueria
                            </ul>
                            <ul class="txtcat">
                                Herramientas
                            </ul>
                            <ul class="txtcat">
                                Prensa
                            </ul>
                        </li>
                    </div>
                    <li>
                        Carrito
                    </li>
                </ul>
                <form>
                    Buscador:
                    <input type="text" id="btnsearch"/>
                    <select>
                        <option value="nombre">Nombre</option>
                        <option value="precio">Precio</option>
                        <option value="categoria">Categoria</option>
                    </select>
                    <input type="submit" value="Go!"/>
                </form>
            </fieldset>

        </div>
        <div id="menu_ppal">
            <%
                try {
                    conn = DriverManager.getConnection(connectionURL);
                    Statement stmt2 = conn.createStatement();
                    ResultSet rs = stmt2.executeQuery(queryString);
                    out.println("<table border=1>");
                    out.println("<th>Nombre</th>");
                    out.println("<th>Imagen</th>");
                    out.println("<th>Precio</th>");
                    out.println("<th>Categoria</th>");
                    while (rs.next()) {
                        out.println("<tr><td>" + rs.getString(1) + "</td>");
                        out.println("<td>" + rs.getString(4) + "</td>");
                        out.println("<td>" + rs.getString(2) + "</td>");
                        out.println("<td>" + rs.getString(3) + "</td></tr>");
                    }
                    out.println("</table>");

                    rs.close();
                } catch (Exception e) {
                    e.getMessage();
                }
            %>
        </div>
    </body>
</html>
